#给定一个二叉搜索树 root 和一个目标结果 k，如果 BST 中存在两个元素且它们的和等于给定的目标结果，则返回 true。
class TreeNode:
    """
    LeetCode官方TreeNode类仿写（模拟官方功能）
    主要用于本地IDE调试
    """
    def __init__(self, val):
        if isinstance(val, list):
            if len(val) == 0:
                self.val = None
            else:
                self.val = val[0]
        elif isinstance(val, int) or isinstance(val, str):
            self.val = val
        self.left = None
        self.right = None

    def gatherAttrs(self):
        return ", ".join("{}: {}".format(k, getattr(self, k)) for k in self.__dict__.keys())

    def __str__(self):
        return self.__class__.__name__ + "{" + "{}".format(self.gatherAttrs()) + "}"
def build_TreeNode(val):
    if val is None:
        return None
    elif isinstance(val, list):
        if len(val) == 0:
            return None
        else:
            head = TreeNode(val[0])
            wait_node_list = [head]
            left = False
            for i in range(1, len(val)):
                node = TreeNode(val[i])
                if not left:
                    if val[i] is not None:
                        wait_node_list[0].left = node
                        wait_node_list.append(node)
                    left = True
                else:
                    if val[i] is not None:
                        wait_node_list[0].right = node
                        wait_node_list.append(node)
                    left = False
                    wait_node_list.pop(0)
            return head
    elif isinstance(val, int) or isinstance(val, str):
        return TreeNode(val)
    else:
        return None
###############################################################################################
class Solution:
    def findTarget(self, root: TreeNode, k: int) -> bool:
        def inorder(root: TreeNode):
            if not root:
                return
            inorder(root.left)
            res.append(root.val)
            inorder(root.right)
        res = list()
        inorder(root)
        n = len(res)
        for i in range (0, n):
            for j in range(i+1,n):
                if res[i]+res[j] == k:
                    return True
        return False